import loginApi from '@/api/login';
import { Modal, Button } from 'antd';
import { useNavigate } from 'react-router-dom';

const LogoutModal = (props: { open: boolean; onCancel: any }) => {
    const link = useNavigate();
    const { open, onCancel } = props;
    const logOut = () => {
        loginApi.logOut(res => {
            if (res.code === 200) {
                sessionStorage.clear();
                link('/login');
            }
        });
    };
    return (
        <Modal width={464} maskClosable={false} centered={true} open={open} closeIcon={<></>}>
            <div className="modal-title">Logout</div>
            <div className="modal-tip" style={{ color: '#666' }}>
                Are you sure you want to log out of the current account?
            </div>
            <div className="submit-btns">
                <Button onClick={onCancel}>Cancel</Button>
                <Button type="primary" onClick={logOut}>
                    Confirm Logout
                </Button>
            </div>
        </Modal>
    );
};
export default LogoutModal;
